package com.silences.servlet;

import com.alibaba.fastjson.JSON;
import com.silences.service.GoodsService;
//import com.silences.service.UserService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;

@WebServlet("/getGoodss")
public class GetGoodsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws javax.servlet.ServletException, IOException {

        //doget
        super.doPost(req,resp);
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws javax.servlet.ServletException, IOException {

        //super.doGet(req,resp);
        //中文乱码问题解决 rep=request resp=response
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");


        //接受前端传递的三个参数
        String searchname=req.getParameter("searchname");
        /*System.out.println(searchname);*/
        String pageIndex=req.getParameter("pageIndex");
        String pageSize=req.getParameter("pageSize");

        //调用service 业务逻辑方法
        GoodsService us=new GoodsService();
        try {
            Map<String,Object> map= us.getGoodss(searchname,pageIndex,pageSize);
            //System.out.println(map.toString());
            resp.getWriter().write(JSON.toJSONString(map).toString());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
